
<template>
    <a-row>
        <a-input-search v-model:value="searchKey" placeholder="请输井ID信息" enter-button="搜索"
            style="width: 250px; margin-bottom: 10px;" @search="onSearch()" />
        <a-button style="margin-left: 10px;" type="dashed" @click="reset">重置</a-button>
    </a-row>
    <!-- 解决方案列表 -->
    <a-table :dataSource="dataSource" size="small" :columns="columns" bordered :pagination="false">
        <template #name="text">
            <a-radio v-model="selectedRowKeys" :value="text">{{ text }}</a-radio>
        </template>
        <template #bodyCell="{ column, text, record }">
            <template v-if="column.title === '操作'">
                <a-button type="link" @click="choose(record)">选择此行</a-button>
                <AntdZh><a-popconfirm title="确定删除该条记录 ?" @confirm="doDelete(record.id)">
                    <a-button type="link" danger>删除</a-button>
                </a-popconfirm></AntdZh>
            </template>
        </template>
    </a-table>
    <AntdZh>
        <a-pagination v-model:current="query.pageNum" v-model:pageSize="query.pageSize" :total="total" @change="getList" />
    </AntdZh>
</template>
<script setup>
import { queryList, deleteOne } from '@/api/salvage/planDesign.js'
import useApp from "@/hooks";
const { $, proxy } = useApp();
const emit = defineEmits(["solutionSelection"]);
const data = reactive({
    form: {}
});
const { form } = toRefs(data);
const dataSource = ref([]);
const total = ref(1)
// 定义表格列配置
const columns = ref([
    {
        title: '井名',
        dataIndex: 'wellId',
        key: 'wellId',
        width: '30%'
    },
    {
        title: '编辑日期',
        dataIndex: 'updatedTime',
        key: 'updatedTime',
        width: '30%'
    },
    {
        title: '操作',
        dataIndex: 'action',
        key: 'action',
    }
])
const searchKey = ref();
const query = ref({ pageNum: 1, pageSize: 10, sortBy: 'id', searchKey: '' });

function choose(item) {
    emit("solutionSelection", item)
}
function doDelete(id) {
    deleteOne(id).then(res => {
        $.showToast({
            title: '删除成功',
            icon: 'success'
        })
        getList()
    })
}
/** 查询方案列表 */
function getList() {
    queryList(query.value).then((response) => {
        dataSource.value = response.content;
        total.value = response.totalElements;
    });
}
getList();

/** 搜索按钮操作 */
function onSearch() {
    query.value.searchKey = searchKey;
    getList();
}

/** 表单重置 */
function reset() {
    searchKey.value = '';
    query.value = { pageNum: 1, pageSize: 10, sortBy: 'id', searchKey: '' }
    getList();
}

</script>
  